{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "74abde73-2161-415d-b956-3f7766ea35e2",
   "metadata": {},
   "source": [
    "*python流程与执行\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a6b5fff1-dc2a-4664-ab92-330c59e2ef2d",
   "metadata": {},
   "source": [
    "**编程语言共性\n",
    "\n",
    "*变量和变量名\n",
    "*变量类型 int float str bool complex\n",
    "*运算符 + - * / > < >= <= == != %(取余) += -= *= /= **（幂运算）\n",
    "*程序执行流程\n",
    " **顺序\n",
    "   程序一行一行执行\n",
    " **循环 \n",
    "   for <循环变量> in range (循环次数):\n",
    "       循环代码\n",
    " **分支"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "1dfe28cf-9cc5-4061-97f9-2c2dc8aacbe4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "bab254dc21214e24bcfc45e038f23d17",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Canvas(width=1000)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import ipyturtle3 as turtle\n",
    "from ipyturtle3 import hold_canvas\n",
    "myCanvas=turtle.Canvas(width=1000,height=500)\n",
    "display(myCanvas)\n",
    "myTS=turtle.TurtleScreen(myCanvas)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "786593cb-4ae0-4912-9dcd-5be313747ac5",
   "metadata": {},
   "outputs": [],
   "source": [
    "myTS=turtle.TurtleScreen(myCanvas)\n",
    "myTS.clear()\n",
    "myTS.bgcolor(\"lightgreen\")\n",
    "bob=turtle.Turtle(myTS)\n",
    "bob.shape(\"turtle\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "71a1b25e-8577-404e-ac92-b1181bf2058c",
   "metadata": {},
   "outputs": [],
   "source": [
    "myTS.delay(0)\n",
    "n=10\n",
    "colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']\n",
    "t = turtle.Turtle(myTS)\n",
    "t.shape(\"turtle\")\n",
    "for _ in range(100):\n",
    "    with(hold_canvas(myCanvas)):\n",
    "        t.pencolor(colors[_%6])\n",
    "    for _ in range(4):\n",
    "        t.forward(n)\n",
    "        t.left(90)\n",
    "    t.left(10)\n",
    "    n+=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "5f5f268b-c7fb-47ff-8835-0a25b3927040",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 1\n",
    "for _ in range(3):\n",
    "  for _ in range(360):\n",
    "      bob.forward(a)\n",
    "      bob.left(1)\n",
    "  a+=0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9aaa1bbf-e5f6-4f14-9fcb-6d13846b9002",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "3ef7ef8a-bb89-43b3-8983-dcb2604b0087",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bd4cbe32-9ecf-40ff-8ccb-38b3ac81d7db",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:base] *",
   "language": "python",
   "name": "conda-base-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
